package com.itcast.framdemo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itcast.framdemo.DTO.EmpDTO;
import com.itcast.framdemo.entity.Emp;
import com.itcast.framdemo.service.IEmpService;
import com.itcast.framdemo.utils.JsonResult;
import com.itcast.framdemo.vo.EmpVO;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/emp")
@Slf4j
public class EmpController {
    /**
     * 实现登录
     * 1,使用jwt
     * 2,使用security
     * 3,
     */
    @Autowired
    private IEmpService empService;

    @PostMapping("/login")
    public JsonResult<EmpVO> login(@RequestBody EmpDTO empDTO){
        log.info("用户登录,数据信息:{}",empDTO);
        EmpVO empVO = empService.login(empDTO);
        return JsonResult.success(empVO);
    }

    @GetMapping
//    @Cacheable(value = "empList",keyGenerator = "myKeyGenerator")
//    @Cacheable(value = "empList",key = "1")
    public JsonResult<IPage<Emp>> getEmpList(HttpServletRequest httpServletRequest){
        log.info("token:{}",httpServletRequest.getHeader("token"));
        IPage<Emp> pageList = empService.getPageList();
        return JsonResult.success(pageList);
    }

    @PutMapping
    public JsonResult updateEmp(){
        log.info("update emp");
        return JsonResult.success();
    }

}
